Page({
  data: {
    deliveryRecords: []
  },

  onLoad: function() {
    this.loadDeliveryRecords()
  },

  onShow: function() {
    this.loadDeliveryRecords()
  },

  loadDeliveryRecords: async function() {
    try {
      const result = await wx.cloud.callFunction({
        name: 'db',
        data: {
          action: 'getDeliveryRecords'
        }
      })

      if (result.result && result.result.records) {
        // 处理状态文本
        const records = result.result.records.map(record => ({
          ...record,
          statusText: this.getStatusText(record.status)
        }))
        
        this.setData({
          deliveryRecords: records
        })
      }
    } catch (error) {
      console.error('获取投递记录失败:', error)
      wx.showToast({
        title: '获取投递记录失败',
        icon: 'none'
      })
    }
  },

  getStatusText: function(status) {
    const statusMap = {
      'pending': '投递成功',
      'viewed': '已查看',
      'rejected': '被拒绝',
      'interview': '待面试',
      'completed': '面试结束'
    }
    return statusMap[status] || '未知状态'
  }
}) 